home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / fwcp / src / key.c < prev    next >
Text File  |  1995-03-14  |  14KB  |  625 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <ctype.h>
  4. #include    <jctype.h>
  5. #include    <string.h>
  6. #include    <malloc.h>
  7. #include    <dos.h>
  8. #include    "defs.h"
  9. #include    "key.h"
  10.  
  11. #define    KEY_BUF_SIZ    256
  12. #define    KEY_BUF_MSK    255
  13.  
  14. static    char    matrix[16];
  15. static    int    key_len=0;
  16. static    int    key_top=0;
  17. static    int    key_pos=0;
  18. static    struct {
  19.     int    ch;
  20.     int    ec;
  21. } key_buf[KEY_BUF_SIZ];
  22.  
  23. static    struct {
  24.     int    mask;
  25.     int    ec;
  26.     int    ch;
  27. } assign[]={
  28.         { 0xFF00, 0x4800, 0x8000 },    /* 挿入 */
  29.         { 0xFF00, 0x4B00, 0x007F },    /* 削除 */
  30.         { 0xFF04, 0x4E00, 0x000B },    /* HOME */
  31.         { 0xFF04, 0x4E04, 0x000C },    /* CLS  */
  32.         { 0xFF00, 0x7300, 0x000D },    /* 実行 */
  33.         { 0xFF00, 0x7200, 0x001B },    /* 取消 */
  34.         { 0xFF00, 0x5D00, 0x8001 },    /* PF1  */
  35.         { 0xFF00, 0x5E00, 0x8002 },    /* PF2  */
  36.         { 0xFF00, 0x5F00, 0x8003 },    /* PF3  */
  37.         { 0xFF00, 0x6000, 0x8004 },    /* PF4  */
  38.         { 0xFF00, 0x6100, 0x8005 },    /* PF5  */
  39.         { 0xFF00, 0x6200, 0x8006 },    /* PF6  */
  40.         { 0xFF00, 0x6300, 0x8007 },    /* PF7  */
  41.         { 0xFF00, 0x6400, 0x8008 },    /* PF8  */
  42.         { 0xFF00, 0x6500, 0x8009 },    /* PF9  */
  43.         { 0xFF00, 0x6600, 0x800A },    /* PF10 */
  44.         { 0xFF00, 0x6900, 0x800B },    /* PF11 */
  45.         { 0xFF00, 0x5B00, 0x800C },    /* PF12 */
  46.         { 0xFF00, 0x7400, 0x800D },    /* PF13 */
  47.         { 0xFF00, 0x7500, 0x800E },    /* PF14 */
  48.         { 0xFF00, 0x7600, 0x800F },    /* PF15 */
  49.         { 0xFF00, 0x7700, 0x8010 },    /* PF16 */
  50.         { 0xFF00, 0x7800, 0x8011 },    /* PF17 */
  51.         { 0xFF00, 0x7900, 0x8012 },    /* PF18 */
  52.         { 0xFF00, 0x7A00, 0x8013 },    /* PF19 */
  53.         { 0xFF00, 0x7B00, 0x8014 },    /* PF20 */
  54.         { 0xFF10, 0x4D10, 0x8017 },    /* ^UP   */
  55.         { 0xFF10, 0x5010, 0x8018 },    /* ^DOWN */
  56.         { 0xFF10, 0x4F10, 0x8019 },    /* ^LEFT */
  57.         { 0xFF10, 0x5110, 0x801A },    /* ^RIGHT*/
  58.         { 0x0000, 0x0000, 0x0000 },
  59.     };
  60.  
  61. static    int    KYB_read(int sw,int *ec)
  62. {
  63.     union REGS regs;
  64.  
  65.     regs.h.ah = 0x09;
  66.     regs.h.al = sw;
  67.     int86(0x90,®s,®s);
  68.     *ec = regs.x.bx;
  69.     return regs.x.dx;
  70. }
  71. static    int    KYB_inpchk(int *ch,int *ec)
  72. {
  73.     union REGS regs;
  74.  
  75.     regs.h.ah = 0x07;
  76.     int86(0x90,®s,®s);
  77.     *ec = regs.x.bx;
  78.     *ch = regs.x.dx;
  79.     return regs.h.al;
  80. }
  81. static    int    KYB_matrix(char *tmp)
  82. {
  83.     union REGS regs;
  84.     struct SREGS seg;
  85.     union {
  86.     char far *p;
  87.     short     s[2];
  88.     } pp;
  89.  
  90.     pp.p = (char far *)(tmp);
  91.     regs.h.ah = 0x0A;
  92.     regs.x.di = pp.s[0];
  93.     seg.ds    = pp.s[1];
  94.     int86x(0x90, ®s, ®s, &seg);
  95.     return regs.h.ah;
  96. }
  97. static    void    NEW_bufset(int ch,int ec)
  98. {
  99.     if ( key_len >= KEY_BUF_SIZ )
  100.     return;
  101.     key_buf[key_top].ch = ch;
  102.     key_buf[key_top].ec = ec;
  103.     key_top++;
  104.     key_top &= KEY_BUF_MSK;
  105.     key_len++;
  106. }
  107. static    int    NEW_inpchk(int *ch,int *ec)
  108. {
  109.     int i, n;
  110.     int ch2, ec2;
  111.     static struct {
  112.         int        on;
  113.         int        ec;
  114.         int        st;
  115.     } ext_tab[] = {
  116.         { 0x8015, 0x7D00, FALSE },        /* COPY  */
  117.         { 0x8016, 0x7C00, FALSE },        /* BREAK */
  118.         { 0x0000, 0x0000, 0 },
  119.     };
  120.  
  121.     KYB_matrix(matrix);
  122.     for ( i = 0 ; (n = ext_tab[i].ec >> 8) != 0 ; i++ ) {
  123.     if ( (matrix[n / 8] & (1 << (n % 8))) != 0 ) {
  124.         if ( ext_tab[i].st == FALSE )
  125.         NEW_bufset(ext_tab[i].on, ext_tab[i].ec);
  126.         ext_tab[i].st = TRUE;
  127.     } else
  128.         ext_tab[i].st = FALSE;
  129.     }
  130.  
  131.     if ( key_len > 0 ) {
  132.     *ch = key_buf[key_pos].ch;
  133.     *ec = key_buf[key_pos].ec;
  134.     return key_len;
  135.     }
  136.  
  137.     *ch = KYB_read(1, ec);
  138.     if ( (*ec & 0xFF00) == 0xFF00 )
  139.     return 0;
  140.  
  141.     for ( i = 0 ; assign[i].ec != 0 ; i++ ) {
  142.     if ( (*ec & assign[i].mask) == assign[i].ec ) {
  143.         while ( KYB_inpchk(&ch2, &ec2) > 0 && *ch != ch2 && *ec == ec2 )
  144.         ch2 = KYB_read(0, &ec2);
  145.         *ch = assign[i].ch;
  146.         NEW_bufset(assign[i].ch, *ec);
  147.         return key_len;
  148.     }
  149.     }
  150.  
  151.     NEW_bufset(*ch, *ec);
  152.     return key_len;
  153. }
  154. static    int    NEW_read(int sw, int *ec)
  155. {
  156.     int     ch=0xFFFF;
  157.  
  158.     do {
  159.     if ( NEW_inpchk(&ch,ec) > 0 ) {
  160.         key_pos++;
  161.         key_pos &= KEY_BUF_MSK;
  162.         key_len--;
  163.         break;
  164.         }
  165.     } while ( sw == 0 );
  166.  
  167.     return ch;
  168. }
  169. int    isank(ch)
  170. int    ch;
  171. {
  172.     return ( !iskanji(ch) && ch >= ' ' && ch != 0x7F );
  173. }
  174. void    tsleep(tic)
  175. int    tic;
  176. {
  177.     union REGS regs;
  178.  
  179.     regs.x.cx = tic * 100;
  180.     int86(0xFD,®s,®s);
  181. }
  182.  
  183. /**********************
  184. ^A=LEFT_CUR
  185. ^B=RIGHT_CUR
  186. ^C=LEFT_NODE
  187. ^D=RIGHT_NODE
  188. PF1=
  189. RIGHT="any strings"
  190. ***********************/
  191.  
  192. static    int    any_ent = 0;
  193. static    int    any_max = 0;
  194. static    char    **any_vct;
  195. static    char    *any_str = NULL;
  196. static struct {
  197.     int    code;
  198.     char    *key;
  199.     } key_name[] = {
  200.     { 0x8000,    "INS" },
  201.     { 0x8001,    "PF1" },
  202.     { 0x8002,    "PF2" },
  203.     { 0x8003,    "PF3" },
  204.     { 0x8004,    "PF4" },
  205.     { 0x8005,    "PF5" },
  206.     { 0x8006,    "PF6" },
  207.     { 0x8007,    "PF7" },
  208.     { 0x8008,    "PF8" },
  209.     { 0x8009,    "PF9" },
  210.     { 0x800A,    "PF10" },
  211.     { 0x800B,    "PF11" },
  212.     { 0x800C,    "PF12" },
  213.     { 0x800D,    "PF13" },
  214.     { 0x800E,    "PF14" },
  215.     { 0x800F,    "PF15" },
  216.     { 0x8010,    "PF16" },
  217.     { 0x8011,    "PF17" },
  218.     { 0x8012,    "PF18" },
  219.     { 0x8013,    "PF19" },
  220.     { 0x8014,    "PF20" },
  221.     { 0x8015,    "COPY" },
  222.     { 0x8016,    "BREAK" },
  223.     { 0x8017,    "^UP" },
  224.     { 0x8018,    "^DOWN" },
  225.     { 0x8019,    "^LEFT" },
  226.     { 0x801A,    "^RIGHT" },
  227.     { 0x001B,    "ESC" },
  228.     { 0x001C,    "LEFT" },
  229.     { 0x001D,    "RIGHT" },
  230.     { 0x001E,    "UP" },
  231.     { 0x001F,    "DOWN" },
  232.     { 0x007F,    "DEL" },
  233.     { 0x0000,    NULL }
  234.     };
  235. static struct {
  236.     int    code;
  237.     char    *str;
  238.     } key_man[] = {
  239.               /* 12345678901234567890 */
  240.     { K_END_OF,    "End of Program" },
  241.     { K_BACK_SPC,    "Edit back space" },
  242.     { K_DEL_CHAR,    "Edit delete char" },
  243.     { K_LEFT_CUR,    "Edit left cursol" },
  244.     { K_RIGHT_CUR,    "Edit right cursol" },
  245.     { K_CUT_BUFF,    "Edit cut line" },
  246.     { K_DEL_LINE,    "Edit delete line" },
  247.     { K_UNDO_LINE,    "Edit paste line" },
  248.     { K_HIS_LINE,    "Edit undo char" },
  249.     { K_END_LINE,    "Edit execute" },
  250.  
  251.     { K_WIND_CNG,    "Wind change" },
  252.     { K_UP_NODE,    "Wind up cursol" },
  253.     { K_DOWN_NODE,    "Wind down cursol" },
  254.     { K_GETS_WIND,    "Edit get act wind" },
  255.     { K_GETS_SRC,    "Edit get src wind" },
  256.     { K_GETS_DIS,    "Edit get dis wind" },
  257.     { K_COPY_WIND,    "Copy src to dis" },
  258.     { K_DIR_MENU,    "Wind chdir menu" },
  259.     { K_SCREEN_FLUSH,"Screen flush" },
  260.     { K_MARK_FILE,    "Wind mark file" },
  261.     { K_INIT_WIND,    "Wind init" },
  262.     { K_MARK_ALL,    "Wind mark all file" },
  263.     { K_SKIP_DOC,    "Wind skip doc file" },
  264.     { K_ABORT,    "Abort" },
  265.  
  266.     { K_CONSOLE,    "DOS Console" },
  267.     { K_HISTORY,    "Edit history" },
  268.     { K_HIS_DIR,    "Wind chdir history" },
  269.     { K_TREE_DIR,    "Wind chdir tree" },
  270.     { K_SORT_MODE,    "Wind disp sort mode" },
  271.     { K_HELP,    "Help screen" },
  272.     { K_DRV_MENU,    "Wind Drive menu" },
  273.  
  274.     { K_UP_MARK,    "Wind mark up node" },
  275.     { K_DOWN_MARK,    "Wind mark down node" },
  276.  
  277.     { 0, NULL },
  278.     };
  279. static struct {
  280.     int    code;
  281.     char    *str;
  282.     } func_name[] = {
  283.     { K_END_OF,    "END_OF" },
  284.     { K_BACK_SPC,    "BACK_SPC" },
  285.     { K_DEL_CHAR,    "DEL_CHAR" },
  286.     { K_LEFT_CUR,    "LEFT_CUR" },
  287.     { K_RIGHT_CUR,    "RIGHT_CUR" },
  288.     { K_CUT_BUFF,    "CUT_BUFF" },
  289.     { K_DEL_LINE,    "DEL_LINE" },
  290.     { K_UNDO_LINE,    "UNDO_LINE" },
  291.     { K_HIS_LINE,    "HIS_LINE" },
  292.     { K_END_LINE,    "END_LINE" },
  293.  
  294.     { K_WIND_CNG,    "WIND_CNG" },
  295.     { K_UP_NODE,    "UP_NODE" },
  296.     { K_DOWN_NODE,    "DOWN_NODE" },
  297.     { K_GETS_WIND,    "GETS_WIND" },
  298.     { K_GETS_SRC,    "GETS_SRC" },
  299.     { K_GETS_DIS,    "GETS_DIS" },
  300.     { K_COPY_WIND,    "COPY_WIND" },
  301.     { K_DIR_MENU,    "DIR_MENU" },
  302.     { K_SCREEN_FLUSH,"SCREEN_FLUSH" },
  303.     { K_MARK_FILE,    "MARK_FILE" },
  304.     { K_INIT_WIND,    "INIT_WIND" },
  305.     { K_MARK_ALL,    "MARK_ALL" },
  306.     { K_SKIP_DOC,    "SKIP_DOC" },
  307.     { K_ABORT,    "ABORT" },
  308.  
  309.     { K_CONSOLE,    "CONSOLE" },
  310.     { K_HISTORY,    "HISTORY" },
  311.     { K_HIS_DIR,    "HIS_DIR" },
  312.     { K_TREE_DIR,    "TREE_DIR" },
  313.     { K_SORT_MODE,    "SORT_MODE" },
  314.     { K_HELP,    "HELP" },
  315.     { K_DRV_MENU,    "DRV_MENU" },
  316.  
  317.     { K_UP_MARK,    "UP_MARK" },
  318.     { K_DOWN_MARK,    "DOWN_MARK" },
  319.  
  320.     { 0x0000,    NULL }
  321.     };
  322.  
  323. #define    CTRL_MAP_LEN    33
  324.  
  325. static    int    ctrl_map[] = {
  326.     K_CONSOLE,        /* ^@ */
  327.     K_HIS_LINE,        /* ^A */
  328.     K_CUT_BUFF,        /* ^B */
  329.     K_INIT_WIND,        /* ^C */
  330.     K_GETS_DIS,        /* ^D */
  331.     EOF,            /* ^E */
  332.     EOF,            /* ^F */
  333.     EOF,            /* ^G */
  334.     K_BACK_SPC,        /* ^H */
  335.     K_WIND_CNG,        /* ^I */
  336.     EOF,            /* ^J */
  337.     EOF,            /* ^K */
  338.     K_SCREEN_FLUSH,        /* ^L */
  339.     K_END_LINE,        /* ^M */
  340.     K_SKIP_DOC,        /* ^N */
  341.     EOF,            /* ^O */
  342.     K_HISTORY,        /* ^P */
  343.     K_MARK_FILE,        /* ^Q */
  344.     K_SORT_MODE,        /* ^R */
  345.     K_GETS_SRC,        /* ^S */
  346.     EOF,            /* ^T */
  347.     K_UNDO_LINE,        /* ^U */
  348.     K_HELP,            /* ^V */
  349.     K_MARK_ALL,        /* ^W */
  350.     K_DEL_LINE,        /* ^X */
  351.     K_DEL_LINE,        /* ^Y */
  352.     K_GETS_WIND,        /* ^Z */
  353.     K_ABORT,        /* ESC */
  354.     K_LEFT_CUR,        /* LEFT */
  355.     K_RIGHT_CUR,        /* RIGHT */
  356.     K_UP_NODE,        /* UP */
  357.     K_DOWN_NODE,        /* DOWN */
  358.     K_DEL_CHAR,        /* DEL */
  359.     };
  360.  
  361. #define    PF_MAP_LEN    27
  362.  
  363. static    int    pf_map[] = {
  364.     EOF,            /* INS */
  365.     K_COPY_WIND,        /* PF1 */
  366.     K_HIS_DIR,        /* PF2 */
  367.     K_DIR_MENU,        /* PF3 */
  368.     K_TREE_DIR,        /* PF4 */
  369.     K_DRV_MENU,        /* PF5 */
  370.     K_MARK_FILE,        /* PF6 */
  371.     K_MARK_ALL,        /* PF7 */
  372.     K_SKIP_DOC,        /* PF8 */
  373.     K_CONSOLE,        /* PF9 */
  374.     K_END_OF,        /* PF10 */
  375.     EOF,            /* PF11 */
  376.     EOF,            /* PF12 */
  377.     EOF,            /* PF13 */
  378.     EOF,            /* PF14 */
  379.     EOF,            /* PF15 */
  380.     EOF,            /* PF16 */
  381.     EOF,            /* PF17 */
  382.     EOF,            /* PF18 */
  383.     EOF,            /* PF19 */
  384.     EOF,            /* PF20 */
  385.     K_COPY_WIND,        /* COPY */
  386.     K_ABORT,        /* BREAK*/
  387.     EOF,            /* ^UP   */
  388.     EOF,            /* ^DOWN */
  389.     EOF,            /* ^LEFT */
  390.     EOF,            /* ^RIGHT*/
  391.     };
  392.  
  393. static    char    *strany(char *str)
  394. {
  395.     int n = 0;
  396.     int c, i;
  397.     static char tmp[LINSIZ + 2];
  398.  
  399.     while ( n < LINSIZ && *str != '\0' ) {
  400.     if ( iskan(str) ) {
  401.         tmp[n++] = *(str++);
  402.         tmp[n++] = *(str++);
  403.     } else if ( *str == '\\' ) {
  404.         str++;
  405.         switch(*(str++)) {
  406.         case 'r':
  407.         case 'n': tmp[n++] = '\r'; break;
  408.         case 'b': tmp[n++] = '\b'; break;
  409.         case 'f': tmp[n++] = '\f'; break;
  410.         case 't': tmp[n++] = '\t'; break;
  411.         case 'x':
  412.         for ( i = c = 0 ; i < 2 && isxdigit(*str) ; i++ ) {
  413.             if ( isdigit(*str) )
  414.             c = c * 16 + (*(str++) - '0');
  415.             else {
  416.             c = c * 16 + (toupper(*str) - 'A' + 10);
  417.             str++;
  418.             }
  419.         }
  420.         tmp[n++] = c;
  421.         break;
  422.         default:
  423.         if ( *str >= '0' && *str <= '7' ) {
  424.             for ( i = c = 0 ; i < 3 &&
  425.                 *str >= '0' && *str <= '7' ; i++ )
  426.             c = c * 8 + (*(str++) - '0');
  427.             tmp[n++] = c;
  428.         } else
  429.             tmp[n++] = *(str - 1);
  430.         break;
  431.         }
  432.     } else {
  433.         tmp[n++] = *(str++);
  434.     }
  435.     }
  436.     tmp[n] = '\0';
  437.     return tmp;
  438. }
  439. static    int    enc_key(char *str)
  440. {
  441.     int n;
  442.  
  443.     for ( n = 0 ; key_name[n].key != NULL ; n++ ) {
  444.     if ( strcmp(str, key_name[n].key) == 0 )
  445.         return key_name[n].code;
  446.     }
  447.  
  448.     if ( *str == '^' )
  449.     return toupper((str[1]) - '@');
  450.     else if ( strncmp(str, "CTRL+", 5) == 0 )
  451.     return toupper((str[5]) - '@');
  452.  
  453.     return EOF;
  454. }
  455. static    int    enc_func(char *str)
  456. {
  457.     int n;
  458.     char *p;
  459.  
  460.     for ( n = 0 ; func_name[n].str != NULL ; n++ ) {
  461.     if ( strcmp(str, func_name[n].str) == 0 )
  462.         return func_name[n].code;
  463.     }
  464.  
  465.     if ( *(str++) == '"' ) {
  466.     if ( (p = strrchr(str, '"')) != NULL )
  467.         *p = '\0';
  468.     if ( any_ent >= any_max ) {
  469.         any_max += 8;
  470.         if ( any_vct == (char **)NULL )
  471.         any_vct = (char **)malloc(sizeof(char *) * any_max);
  472.         else
  473.         any_vct = (char **)realloc(any_vct, sizeof(char *) * any_max);
  474.  
  475.         if ( any_vct == (char **)NULL ) {
  476.         fprintf(stderr, "key strings malloc error\n");
  477.         exit(1);
  478.         }
  479.         any_vct[any_ent] = strdup(str);
  480.     }
  481.     return (K_STRING + (any_ent++));
  482.     }
  483.  
  484.     return EOF;
  485. }
  486. static    char    *key_str(int code)
  487. {
  488.     int n;
  489.     static char tmp[8];
  490.  
  491.     for ( n = 0 ; key_name[n].key != NULL ; n++ ) {
  492.     if ( code == key_name[n].code )
  493.         return key_name[n].key;
  494.     }
  495.     sprintf(tmp, "^%c", code + '@');
  496.     return tmp;
  497. }
  498. static    char    *key_cmd(int code)
  499. {
  500.     int n;
  501.  
  502.     for ( n = 0 ; key_man[n].str != NULL ; n++ ) {
  503.     if ( code == key_man[n].code )
  504.         return key_man[n].str;
  505.     }
  506.  
  507.     if ( code >= K_STRING )
  508.     return any_vct[code - K_STRING];
  509.  
  510.     return "";
  511. }
  512. void    key_map()
  513. {
  514.     int n, c;
  515.     int x = 0, y = 2;
  516.  
  517.     for ( n = 0 ; n < CTRL_MAP_LEN ; n++ ) {    /* ctrl_map */
  518.     c = (n == 32 ? 0x7F : n);
  519.     LOCATE(x, y);
  520.     FPUTS("%-5s %-20.20s", key_str(c), key_cmd(ctrl_map[n]));
  521.     if ( ++y > (SCR_Y - 2) ) {
  522.         y = 2;
  523.         x += 26;
  524.     }
  525.     }
  526.     for ( n = 0 ; n < PF_MAP_LEN ; n++ ) {    /* pf_map */
  527.     c = 0x8000 | n;
  528.     LOCATE(x, y);
  529.     FPUTS("%-5s %-20.20s", key_str(c), key_cmd(pf_map[n]));
  530.     if ( ++y > (SCR_Y - 2) ) {
  531.         y = 2;
  532.         x += 26;
  533.     }
  534.     }
  535. }
  536. int     REALCH()
  537. {
  538.     int     ec;
  539.  
  540.     if ( any_str != NULL ) {
  541.     if ( *any_str != '\0' )
  542.         return (*(any_str++) & 0x00FF);
  543.     any_str = NULL;
  544.     }
  545.  
  546.     return NEW_read(0, &ec);
  547. }
  548. int    GETCH()
  549. {
  550.     int ch;
  551.  
  552. LOOP:
  553.     do {
  554.         ch = REALCH();
  555.         if ( (ch & 0xFF00) != 0 ) {
  556.         if ( (ch & 0xFF00) == 0x8000 && (ch & 0x00FF) < PF_MAP_LEN )
  557.             ch = pf_map[ch & 0x00FF];
  558.         else
  559.         ch = EOF;
  560.         } else if ( ch < ' ' )
  561.         ch = ctrl_map[ch];
  562.         else if ( ch == 0x007F )
  563.         ch = ctrl_map[32];
  564.     } while ( ch == EOF );
  565.  
  566.     if ( ch >= K_STRING ) {
  567.     any_str = strany(any_vct[ch - K_STRING]);
  568.     goto LOOP;
  569.     }
  570.  
  571.     return ch;
  572. }
  573. void    UNGETCH(int ch)
  574. {
  575.     if ( any_str != NULL )
  576.     any_str--;
  577.     else
  578.     NEW_bufset(ch, 0);
  579. }
  580. int    KBHIT()
  581. {
  582.     int     ch,ec;
  583.  
  584.     if ( any_str != NULL && *any_str != '\0' )
  585.     return 1;
  586.     else
  587.         return NEW_inpchk(&ch, &ec);
  588. }
  589.  
  590. void    key_defs(FILE *fp, char *tmp)
  591. {
  592.     int  ch;
  593.     char *p;
  594.  
  595.     while ( fgets(tmp, LINSIZ, fp) != NULL ) {
  596.     if ( (p = strchr(tmp, '\n')) != NULL )
  597.         *p = '\0';
  598.         if ( strcmp(tmp, "#end") == 0 )
  599.             break;
  600.     if ( (p = strchr(tmp, '=')) == NULL )
  601.         continue;
  602.     *(p++) = '\0';
  603.     while ( isspace(*p) )
  604.         p++;
  605.     if ( (ch = enc_key(tmp)) == EOF )
  606.         continue;
  607.  
  608.     if ( (ch & 0xFF00) == 0 && ch < ' ' )
  609.         ctrl_map[ch] = enc_func(p);
  610.     else if ( ch == 0x007F )
  611.         ctrl_map[32] = enc_func(p);
  612.     else if ( (ch & 0x00FF) < PF_MAP_LEN )
  613.         pf_map[ch & 0x00FF] = enc_func(p);
  614.     }
  615. }
  616. void    KEYINIT()
  617. {
  618. }
  619. void    KEYEND()
  620. {
  621. }
  622. void    setkey()
  623. {
  624. }
  625.